import wepy from 'wepy'
import { api } from './config'
import { requestData } from './util'

  //加密数据进行解密认证
  export const decode = (params) => {
  return new Promise((resolve, reject) => {
    requestData({
      url: api.user.decode.url,
      method: api.user.decode.method,
      header: {
        Accept: 'application/json',
        'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
      },
      data: params
    }, function(data) {
      resolve(data)
    }, function(error) {
      resolve(error)
    })
  })
}

  export const getMemberInfo = (ID, accessToken) => {
  return new Promise((resolve, reject) => {
    requestData({
      url: api.user.member.url + `/${ID}?accessToken=${accessToken}`,
      method: api.user.member.method,
      header: {
        Accept: 'application/json',
        'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
      },
    }, function(data) {
      resolve(data)
    }, function(error) {
      resolve(error)
    })
  })
}

  export const setMemberInfo = (ID, accessToken) => {
  return new Promise((resolve, reject) => {
    requestData({
      url: api.user.member.url + `/${ID}?accessToken=${accessToken}`,
      method: 'POST',
      header: {
        Accept: 'application/json',
        'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
      },
    }, function(data) {
      resolve(data)
    }, function(error) {
      resolve(error)
    })
  })
}

  //实名认证
  export const authentication = (params, accessToken) => {
  return new Promise((resolve, reject) => {
    requestData({
      url: api.user.authentication.url + `?accessToken=${accessToken}`,
      method: api.user.authentication.method,
      header: {
        Accept: 'application/json',
        'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
      },
      data: params
    }, function(data) {
      resolve(data)
    }, function(error) {
      resolve(error)
    })
  })
}

  //实名认证获取待审核数据
  export const AuthenticationAuditing = (params) => {
  return new Promise((resolve, reject) => {
    requestData({
      url: api.user.authentication.url,
      method: 'GET',
      header: {
        Accept: 'application/json',
        'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
      },
      data: params
    }, function(data) {
      resolve(data)
    }, function(error) {
      resolve(error)
    })
  })
}

  //手机发送验证码
  export const sendCode = (params) => {
  return new Promise((resolve, reject) => {
    requestData({
      url: api.user.sendCode.url,
      method: api.user.sendCode.method,
      header: {
        Accept: 'application/json',
        'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
      },
      data: params
    }, function(data) {
      resolve(data)
    }, function(error) {
      resolve(error)
    })
  })
}

  // export const contractUpload = (params, accessToken) => {
//   return new Promise((resolve, reject) => {
//     requestData({
//       url: api.user.authentication.url + `?accessToken=${accessToken}`,
//       method: "GET",
//       header: {
//         Accept: 'application/json',
//         'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
//       },
//       data: params
//     }, function(data) {
//       resolve(data)
//     }, function(error) {
//       reject(error)
//     })
//   })
// }

  export const imagesUpload = (params, accessToken) => {
  return new Promise((resolve, reject) => {
    requestData({
      url: `https://as365.try0574.com/api/file/upload-images?accessToken=${accessToken}`,
      method: api.upload.imagesUpload.method,
      header: {
        Accept: 'application/json',
        'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
      },
      data: params
    }, function(data) {
      resolve(data)
    }, function(error) {
      resolve(error)
    })
  })
}

  export const videosUpload = (params, accessToken) => {
  return new Promise((resolve, reject) => {
    requestData({
      url: api.upload.videosUpload.url + `?accessToken=${accessToken}`,
      method: api.upload.videosUpload.method,
      header: {
        Accept: 'application/json',
        'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
      },
      data: params
    }, function(data) {
      resolve(data)
    }, function(error) {
      resolve(error)
    })
  })
}

  export const base64Upload = (params, accessToken) => {
  return new Promise((resolve, reject) => {
    requestData({
      url: api.upload.base64Upload.url + `?accessToken=${accessToken}`,
      method: api.upload.base64Upload.method,
      header: {
        Accept: 'application/json',
        'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
      },
      data: params
    }, function(data) {
      resolve(data)
    }, function(error) {
      resolve(error)
    })
  })
}

  // 获取政策法规
  export const getRegulation = (params) => {
  return new Promise((resolve, reject) => {
    requestData({
      url: api.regulation.getRegulation.url,
      method: api.regulation.getRegulation.method,
      header: {
        Accept: 'application/json',
        'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
      },
      data: params
    }, function(data) {
      resolve(data)
    }, function(error) {
      resolve(error)
    })
  })
}

  // 获取政策法规详情
  export const regulationDetail = (ID,accessToken) => {
  return new Promise((resolve, reject) => {
    requestData({
      url: api.regulation.regulationDetail.url+ID+`?accessToken=${accessToken}`,
      method: api.regulation.regulationDetail.method,
      header: {
        Accept: 'application/json',
        'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
        accessToken: wepy.getStorageSync('token')
      },
    }, function(data) {
      resolve(data)
    }, function(error) {
      resolve(error)
    })
  })
}

  // 合同下载 列表
  export const contractDownLoadList = (params) => {
  return new Promise((resolve, reject) => {
    requestData({
      url: api.contract.contractDownLoad.url,
      method: api.contract.contractDownLoad.method,
      header: {
        Accept: 'application/json',
        'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
      },
      data: params
    }, function(data) {
      resolve(data)
    }, function(error) {
      resolve(error)
    })
  })
}

  // 合同监理列表
  export const contractSupervisorList = (params) => {
  return new Promise((resolve, reject) => {
    requestData({
      url: api.contract.supervisor.url,
      method: api.contract.supervisor.method,
      header: {
        Accept: 'application/json',
        'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
      },
      data: params
    }, function(data) {
      resolve(data)
    }, function(error) {
      resolve(error)
    })
  })
}

  // 合同监理创建
  export const contractSupervisor = (params,accessToken) => {
  return new Promise((resolve, reject) => {
    requestData({
      url: api.contract.contractSupervisor.url+`?accessToken=${accessToken}`,
      method: api.contract.contractSupervisor.method,
      header: {
        Accept: 'application/json',
        'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
      },
      data: params
    }, function(data) {
      resolve(data)
    }, function(error) {
      resolve(error)
    })
  })
}

  // 建立合同
  export const newContract = (params,ID,accessToken) => {
  return new Promise((resolve, reject) => {
    requestData({
      url: api.contract.contractSupervisor.url+`/${ID}?accessToken=${accessToken}`,
      method: 'PUT',
      // header: {
      //   Accept: 'application/json',
      //   'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
      // },
      data: params
    }, function(data) {
      resolve(data)
    }, function(error) {
      resolve(error)
    })
  })
}

  //获取舆论列表
  export const contractConsensus = (params) =>{
  return new Promise((resolve,reject) => {
    requestData({
      url:api.publicOption.consensus.url,
      method:api.publicOption.consensus.method,
      header:{
        Accept:'application/json',
        'Content-Type':'application/x-www-form-urlencoded; charset=utf-8'
      },
      data:params
    }, function(data){
      resolve(data)
    },function(error){
      resolve(error)
    }
    )
  })
}

//获取舆论详情
  export const consensusDetail = (ID,accessToken) => {
    return new Promise((resolve,reject) => {
      requestData({
      url:api.publicOption.consensusDetail.url+ID+'?accessToken='+accessToken,
      method:api.publicOption.consensusDetail.method,
      header:{
          Accept:'application/json',
          'Content-Type':'application/x-www-form-urlencoded; charset=utf-8'
        },
      }, function(data){
        resolve(data)
      },function(error){
        resolve(error)
      })
    })
  }

  //舆论修改
  export const consensusModify = (ID,accessToken,imageUrl) => {
    return new Promise((resolve,reject) => {
      requestData({
      url:api.publicOption.consensusModify.url+ID+'?accessToken='+accessToken+'&evidence_cover='+imageUrl,
      method:api.publicOption.consensusModify.method,
      header:{
          Accept:'application/json',
          'Content-Type':'application/x-www-form-urlencoded; charset=utf-8'
        },
        //data:params
      }, function(data){
        resolve(data)
      },function(error){
        resolve(error)
      })
    })
  }

  //获取招标列表
  export const getBiddingList = (params) => {
    return new Promise((resolve,reject) => {
      requestData({
      url:api.bidding.biddinglist.url,
      method:api.bidding.biddinglist.method,
      header:{
          Accept:'application/json',
          'Content-Type':'application/x-www-form-urlencoded; charset=utf-8'
        },
        data:params
      }, function(data){
        resolve(data)
      },function(error){
        resolve(error)
      })
    })
  }

  //接单
  export const recieptBid = (params,accessToken) => {
    return new Promise((resolve,reject) => {
      requestData({
      url:api.bidding.recieptbidding.url+`?accessToken=${accessToken}`,
      method:api.bidding.recieptbidding.method,
      header:{
          Accept:'application/json',
          'Content-Type':'application/x-www-form-urlencoded; charset=utf-8'
        },
        data:params
      }, function(data){
        resolve(data)
      },function(error){
        resolve(error)
      })
    })
  }

  //获取人脉
  export const getConnection = (accessToken) => {
    return new Promise((resolve,reject) => {
      requestData({
      url:api.connection.connectionlist.url+'?accessToken='+accessToken,
      method:api.connection.connectionlist.method,
      header:{
          Accept:'application/json',
          'Content-Type':'application/x-www-form-urlencoded; charset=utf-8'
        },
      }, function(data){
        resolve(data)
      },function(error){
        resolve(error)
      })
    })
  }

  //获取积分明细
  export const getIntegral = (params) => {
    return new Promise((resolve,reject) => {
      requestData({
      url:api.connection.integrallist.url,
      method:api.connection.integrallist.method,
      header:{
          Accept:'application/json',
          'Content-Type':'application/x-www-form-urlencoded; charset=utf-8'
        },
      data:params
      }, function(data){
        resolve(data)
      },function(error){
        resolve(error)
      })
    })
  }

  //获取消息列表
  export const getNotify = (params) => {
    return new Promise((resolve,reject) => {
      requestData({
      url:api.connection.notifylist.url,
      method:api.connection.notifylist.method,
      header:{
          Accept:'application/json',
          'Content-Type':'application/x-www-form-urlencoded; charset=utf-8'
        },
      data:params
      }, function(data){
        resolve(data)
      },function(error){
        resolve(error)
      })
    })
  }

  //获取律师列表
  export const getLawyer = (params) => {
    return new Promise((resolve,reject) => {
      requestData({
      url:api.lawyerdata.lawyerList.url,
      method:api.lawyerdata.lawyerList.method,
      header:{
          Accept:'application/json',
          'Content-Type':'application/x-www-form-urlencoded; charset=utf-8'
        },
        data:params
      }, function(data){
        resolve(data)
      },function(error){
        resolve(error)
      })
    })
  }

  //获取律师详情
  export const getLawyerDetail = (ID,accessToken) => {
    return new Promise((resolve,reject) => {
      requestData({
      url:api.lawyerdata.lawyerDetail.url+ID+'?accessToken='+accessToken,
      method:api.lawyerdata.lawyerDetail.method,
      header:{
          Accept:'application/json',
          'Content-Type':'application/x-www-form-urlencoded; charset=utf-8'
        },
      }, function(data){
        resolve(data)
      },function(error){
        resolve(error)
      })
    })
  }

  //获取律师评分
  export const getLawyerScoreList = (params) => {
    return new Promise((resolve,reject) => {
      requestData({
      url:api.lawyerdata.lawyerScoreList.url,
      method:api.lawyerdata.lawyerScoreList.method,
      header:{
          Accept:'application/json',
          'Content-Type':'application/x-www-form-urlencoded; charset=utf-8'
        },
        data:params
      }, function(data){
        resolve(data)
      },function(error){
        resolve(error)
      })
    })
  }

  //获取律师所得费用列表
  export const getLawyerMoneyList = (params,accessToken) => {
    return new Promise((resolve,reject) => {
      requestData({
      url:api.lawyerdata.lawyerMoneyList.url + '?accessToken='+ accessToken,
      method:api.lawyerdata.lawyerMoneyList.method,
      header:{
          Accept:'application/json',
          'Content-Type':'application/x-www-form-urlencoded; charset=utf-8'
        },
        data:params
      }, function(data){
        resolve(data)
      },function(error){
        resolve(error)
      })
    })
  }
  
  //支付用户获得支付列表
  export const getUserPayInfo = (params, accessToken) => {
    return new Promise((resolve,reject) => {
      requestData({
          url:api.lawyerdata.lawyerMoneyList.url + '?accessToken='+ accessToken,
          method:api.lawyerdata.lawyerMoneyList.method,
          header:{
              Accept:'application/json',
              'Content-Type':'application/x-www-form-urlencoded; charset=utf-8'
          },
          data:params
      }, function(data) {
        resolve(data)
      },function(error) {
        resolve(error)
      })
    })
  }

  //律师获得费用
  export const postLawyerMoney = (params) => {
    return new Promise((resolve,reject) => {
      requestData({
      url:api.lawyerdata.giveLawyerMoney.url,
      method:api.lawyerdata.giveLawyerMoney.method,
      header:{
          Accept:'application/json',
          'Content-Type':'application/x-www-form-urlencoded; charset=utf-8'
        },
        data:params
      }, function(data){
        resolve(data)
      },function(error){
        resolve(error)
      })
    })
  }

  //获取律师文章列表
  export const getLawyerArticleList = (params) => {
    return new Promise((resolve,reject) => {
      requestData({
      url:api.lawyerdata.lawyerArticleList.url,
      method:api.lawyerdata.lawyerArticleList.method,
      header:{
          Accept:'application/json',
          'Content-Type':'application/x-www-form-urlencoded; charset=utf-8'
        },
        data:params
      }, function(data){
        resolve(data)
      },function(error){
        resolve(error)
      })
    })
  }

  //整合信息
  export const getUserInfo = (ID,accessToken) => {
    return new Promise((resolve,reject) => {
      requestData({
      url:api.lawyerdata.lawyerinfo.url+ID+"?accessToken="+accessToken,
      method:api.lawyerdata.lawyerinfo.method,
      header:{
          Accept:'application/json',
          'Content-Type':'application/x-www-form-urlencoded; charset=utf-8'
        },
      }, function(data){
        resolve(data)
      },function(error){
        resolve(error)
      })
    })
  }

  //整合省市
  export const getProvincesList = (accessToken) => {
    return new Promise((resolve,reject) => {
      requestData({
      url:api.lawyerdata.provincesList.url+"?accessToken="+accessToken,
      method:api.lawyerdata.provincesList.method,
      header:{
          Accept:'application/json',
          'Content-Type':'application/x-www-form-urlencoded; charset=utf-8'
        },
      }, function(data){
        resolve(data)
      },function(error){
        resolve(error)
      })
    })
  }

  //我的账户中的  我的招标列表
  export const getTender = (accessToken) => {
    return new Promise((resolve,reject) => {
      requestData({
      url:api.bidding.tender.url+"?accessToken="+accessToken,
      method:api.bidding.tender.method,
      header:{
          Accept:'application/json',
          'Content-Type':'application/x-www-form-urlencoded; charset=utf-8'
        },
      }, function(data){
        resolve(data)
      },function(error){
        resolve(error)
      })
    })
  }

  //用户消费余额
  export const userPay = (params, accessToken) => {
      return new Promise((resolve, reject) => {
          requestData({
              url: api.user.userPay.url + `?accessToken=${accessToken}`,
              method: api.user.userPay.method,
              header: {
                  Accept: 'application/json',
                  'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
              },
              data: params
          }, function(data) {
              resolve(data)
          }, function(error) {
              resolve(error)
          })
      })
  }